<script setup lang="ts">
import {computed, inject, ref, watch,render,h} from "vue";
import {Message} from "@arco-design/web-vue";
import delivery from "@/api/warehouse/delivery.js";
import AddModalForm from "@/views/warehouse/delivery/components/addModalForm.vue";

const size = ref('small');
const crudRef = inject('crudRef')
const record = inject('record')
const getDictData = inject('getDictData')
const refreshRecode = inject('refreshRecode')
const columnsDist = inject('columnsDist')//全部字典
const addModalMormRef = ref()
const InfoDataLeft = ref([])
const InfoDataMiddle = ref([])
const InfoDataRight = ref([])
const audit = ref(1)


//重新加载
const resetGetRecord=(e)=>{
  refreshRecode()
  }
// const edit = ()=>crudRef.value.crudFormRef.edit(record.value)
const edit=()=>{
  addModalMormRef.value.onShow(record.value)
}
watch(record, (value) => {
  if(value.id == undefined){
    return;
  } 
  audit.value = record.value.status
  console.log('刷新基础信息--'+record.value.id)
   InfoDataLeft.value =  [
      {label: '供应商服务：', value: getDictData('attrApi','dicthelpApi_supplier',record.value.supplier_service_id,3,columnsDist.value)},
      {label: '发往站点：', value: getDictData('attrApi','dicthelpApi_depot',record.value.to_depot_id,3,columnsDist.value)},
      {label: '类型：', value: record.value.type==1 ? '大货':'包裹'},
      {label: '发出时间：', value: record.value.send_date},
    ]
   InfoDataMiddle.value =  [
      {label: '参考号：', value: record.value.reference,slotName: 'from_depot_id',},
      {label: '主品名：', value: record.value.name},
      {label: '出口报关：', value: record.value.declaration == 1 ? '是':''},
      {label: '单独清关：', value: record.value.clearance == 1 ? '是':''},
    ]
   InfoDataRight.value = [
       {label: '分货标签：', value: getDictData('tags','dicthelpApi_tagsType',record.value.tags,3,columnsDist.value)},
      {label: '分货备注：', value: record.value.distribut_mark,},
      {label: '备注：', value: record.value.remark,},
    ]
},{
  immediate:true,
  deep: true
})
const closeOrder = async ()=>{
  const res = await delivery.closeOrderPass({id:record.value.id})
  if(res.success){
    record.value.close = true
    Message.success(res.message)
  }else{
    Message.error(res.message)
  }
}
</script>
<template>
  <a-grid-item :span="24">
    <a-collapse :default-active-key="['1']" class="g-collapse">
      <a-collapse-item header="基础信息" key="1">
        <template #extra>
          <a-button-group>
            <a-button type="primary" size="small" @click.stop="edit" a-auth="['warehouse:delivery:update']"><icon-edit/>编辑</a-button>
            <!-- <a-button type="primary" size="small" @click.stop=""><icon-download/>托盘</a-button> -->
            <a-popconfirm v-if="record.close == false"
            content="确定配货完成了吗?"
            position="bottom"
            @click.stop=""
            @ok="closeOrder()"
            >
            <a-button type="primary" status="danger" size="small"  v-auth="['warehouse:delivery:closeOrderPass']">完成配货</a-button>
            </a-popconfirm>
            <a-button v-else type="" size="small" >配货结束</a-button>
          </a-button-group>
        </template>
        <a-row class="">
          <a-col :span="8">
            <a-descriptions  :data="InfoDataLeft" :size="size" :column="1"  />
          </a-col>
          <a-col :span="8">
            <a-descriptions  :data="InfoDataMiddle" :size="size" :column="1"  />
          </a-col>
          <a-col :span="8">
            <a-descriptions  :data="InfoDataRight" :size="size" :column="1"  />
          </a-col>
        </a-row>
      </a-collapse-item>
    </a-collapse>
  </a-grid-item>
  <add-modal-form  @emitClick="resetGetRecord" ref="addModalMormRef"></add-modal-form>
</template>

<style scoped>

</style>